<template>
	<view class="container">
		<view class="list-cell b-b m-t" @click="navTo('./userInfo')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">{{$t('user.name10')}}</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell b-b" @click="navTo('/pageA/setList/setList')" hover-class="cell-hover"
			:hover-stay-time="50">
			<text class="cell-tit">{{$t('user.name11')}}</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<!-- #ifdef APP-PLUS -->
		<view class="list-cell  b-b " @click="navTo('../makemode/makemode')" hover-class="cell-hover"
			:hover-stay-time="50">
			<text class="cell-tit">{{$t('title')}}</text>
			<text class="cell-tip" style="color: #5990FF;">{{version}}</text>
		</view>
		<!-- #endif -->
		<view class="list-cell  b-b " @click="show = true" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">{{$t('user.name13')}}</text>
			<view class="">
				<text class="cell-tip"
					style="color: #1D93FF;">{{lang}}</text>
				<text class="cell-more yticon icon-you"></text>
			</view>
		</view>
		<view class="list-cell  b-b" @click="navTo(`/pageB/noticeList/noticeInfo?name=${$t('user.name14')}&type=15`)"
			hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">{{$t('user.name14')}}</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell  b-b" @click="navTo(`/pageB/noticeList/noticeInfo?name=${$t('user.name15')}&type=16`)"
			hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">{{$t('user.name15')}}</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell  b-b" @click="downshow=true" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">APP{{$t('user.name75')}}</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<!-- <view class="list-cell   b-b " @click="navTo('cancellation')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">{{$t('user.name19')}}</text>
			<text class="cell-more yticon icon-you"></text>
		</view> -->
		<view class="list-cell   b-b " @click="navTo('./changeUser')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">{{$t('user.name16')}}</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="bq">
			<view>Copyright©2022-2032</view>
			<view>{{$t('title')}} {{baseUrl}}{{$t('user.name76')}}</view>
		</view>
		<view class="quit-login" @click="toLogout">
			<text>{{$t('user.name17')}}</text>
		</view>
		<u-overlay :show="downshow" @click="downshow = false">
			<view class="warp">
				<uqrcode ref="uqrcode" @complete="complete($event)" canvas-id="qrcode" size="150" :value="downUrl"
					:options="{
				  foreground: {
					image: {
					  src: '/static/login_logo.png',
					  width: 40.25,
					  height: 40.25,
					  align: ['center', 'center'],
					  anchor: [0, 0]
					}
				  }
				}">
				</uqrcode>
			</view>
		</u-overlay>
		<u-popup :show="show" @close="show = false" mode="center" round="10" bgColor="rgba(75, 75, 75, 0.5)">
			<view class="lang" style="width: 500rpx;color: #fff;text-align: center;">
				<view class="title">{{$t('lang.togger')}}</view>
				<view :class="['item',_i18n.locale == 'zh-cn'?'active':'']" @click="setLang('zh-cn',$t('lang.zh'))">{{$t('lang.zh')}}</view>
				<view :class="['item',_i18n.locale == 'zh-tw'?'active':'']" @click="setLang('zh-tw',$t('lang.zhtw'))">{{$t('lang.zhtw')}}</view>
				<view :class="['item',_i18n.locale == 'zh-en'?'active':'']" @click="setLang('zh-en',$t('lang.en'))">{{$t('lang.en')}}</view>
				<view :class="['item',_i18n.locale == 'zh-rw'?'active':'']" @click="setLang('zh-rw',$t('lang.jp'))">{{$t('lang.jp')}}</view>
				<view :class="['item',_i18n.locale == 'zh-hw'?'active':'']" @click="setLang('zh-hw',$t('lang.ko'))">{{$t('lang.ko')}}</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import env from "@/util/env.js";
	import {
		mapMutations
	} from 'vuex';
	import enLocale from "@/common/locales/en.js";
	import zhLocale from "@/common/locales/zh.js";
	import twLocale from "@/common/locales/zh-tw.js";
	export default {
		data() {
			return {
				userInfo: {},
				version: '',
				baseUrl: env.prod.baseUrl,
				downshow: false,
				downUrl: '',
				show:false,
				lang:''
			};
		},
		onReady() {
			uni.setNavigationBarTitle({
				title: this.$t('user.name23')
			})
		},
		onLoad() {
			this.lang=uni.getStorageSync('lang')||this.$t('lang.zh')
			this.$fun.ajax.post('index/config', {}).then(res => {
				this.loginList = res.data.login
				this.downUrl = res.data.download_address
			})
		},
		onShow() {

			// #ifdef APP-PLUS
			plus.runtime.getProperty(plus.runtime.appid, async (inf) => {
				this.version = 'V' + inf.version
				console.log('当前版本', inf.version);
			})
			// #endif
			this.getInfo()
		},
		methods: {
			...mapMutations(['logout']),
			setLang(val,lang) {
				if (this._i18n.locale == val) return
				// 切换为英文
				this._i18n.locale = val
				this.lang=lang
				uni.setStorageSync('language', val)
				uni.setStorageSync('lang', lang)
				if(val=='zh-cn'){
					uni.setLocale('zh-Hans')
				}else if(val=='zh-tw'){
					uni.setLocale('zh-Hant')
				}else {
					uni.setLocale('en')
				}
				// const  message = this._i18n.locale === 'en' ? enLocale : zhLocale
				// this._i18n.setLocaleMessage(val,message)   //无感刷新
				this.show = false
				this.$fun.msg(this.$t('user.name22'))
				uni.setNavigationBarTitle({
					title: this.$t('user.name23')
				})
			},
			account_change() {
				uni.navigateTo({
					url: '/pages/changeAccount/changeAccount'
				})
			},
			complete(e) {
				if (e.success) {
					console.log('生成成功');
				} else {
					console.log('生成失败');
				}
			},
			navTo(url) {
				if (url == 'cancellation') {
					uni.showModal({
						content: this.$t('user.name18'),
						success: (e) => {
							if (e.confirm) {
								this.$fun.msg(this.$t('user.name19'))
								uni.clearStorage()
								setTimeout(() => {
									uni.reLaunch({
										url: '/pageA/public/login'
									})
								}, 200)
							}
						}
					});
					return
				}
				if (url == 'wx') {
					location.href = this.$wxLogin
				}
				uni.navigateTo({
					url
				})
			},
			//重新获取用户信息
			getInfo() {
				this.$fun.ajax.post('user/index', {}).then(res => {
					this.userInfo = res.data
					this.balance = res.data.balance
				})
			},
			//退出登录
			toLogout() {
				uni.showModal({
					content: this.$t('user.name20'),
					success: (e) => {
						if (e.confirm) {
							this.$fun.msg(this.$t('user.name21'))
							uni.clearStorage()
							setTimeout(() => {
								uni.reLaunch({
									url: '/pageA/public/login'
								})
							}, 200)
						}
					}
				});
			},
			//switch
			switchChange(e) {
				let statusTip = e.detail.value ? '打开' : '关闭';
				this.$api.msg(`${statusTip}消息推送`);
			},

		}
	}
</script>

<style lang='scss'>
	.lang {
		.title {
			font-size: 34rpx;
			font-weight: 600;
			margin: 30rpx 0 50rpx 0;
		}
	
		.item {
			font-size: 30rpx;
			height: 100rpx;
			line-height: 100rpx;
		}
	
		.active {
			background-color: rgb(48, 158, 248);
			font-weight: 600;
		}
	}
	.account_change {
		width: 100%;
		text-align: center;
		position: absolute;
		bottom: 50rpx;
		left: 0;
		right: 0;
		margin: auto;
		color: rgb(0, 122, 255);
	}

	page {
		background: #f5f5f5;
		;
	}

	.list-cell {
		display: flex;
		align-items: baseline;
		padding: 20upx 32upx;
		line-height: 60upx;
		position: relative;
		background: #fff;
		justify-content: center;

		&.log-out-btn {
			margin-top: 40upx;

			.cell-tit {
				color: #333333;
				text-align: center;
				margin-right: 0;
				font-size: 20rpx;
			}
		}

		&.cell-hover {
			background: #fafafa;
		}

		&.b-b:after {
			left: 30upx;
		}

		&.m-t {
			margin-top: 16upx;
		}

		.cell-more {
			align-self: baseline;
			font-size: 26upx;
			color: #909399;
			margin-left: 10upx;
		}

		.cell-tit {
			flex: 1;
			font-size: 30rpx;
			color: #333333;
			margin-right: 10upx;
		}

		.cell-tip {
			font-size: 30rpx;
			color: #333333;
			margin-right: 10upx;
		}

		switch {
			transform: translateX(16upx) scale(.84);
		}
	}

	.bq {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 130rpx;
		margin: auto;

		view {
			text-align: center;
		}
	}

	.warp {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 100%;

		.btn {
			display: flex;
			justify-content: space-between;
			margin: 40rpx auto 0;

			.btnclose {
				width: 230rpx;
				height: 64rpx;
				line-height: 64rpx;
				text-align: center;
				border-radius: 32rpx;
				border: 2rpx solid #5D78FF;
				font-weight: 500;
				color: #5D78FF;
				font-size: 28rpx;

			}

			.btnsure {
				width: 230rpx;
				height: 64rpx;
				line-height: 64rpx;
				text-align: center;
				background: #5D78FF;
				border-radius: 32rpx;
				font-weight: 500;
				font-size: 28rpx;
				color: #FFFFFF;
			}
		}
	}

	/* 退出登录 */
	.quit-login {
		position: fixed;
		left: 0;
		bottom: 0;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
		height: 100rpx;
		background: #FFFFFF;
		border-radius: 20rpx;

		text {
			color: #222222;
			font-size: 28rpx;
		}
	}
</style>